<script>
	import {websocetObj} from "@/utils/websocket.js"
	export default {
		onLaunch: function(options) {
			uni.setStorageSync('isFirstLaunch', true)
			// #ifdef MP-WEIXIN
			const launchOptions = wx.getLaunchOptionsSync().query
			console.log('launchOptions：', launchOptions);
			uni.login({
				success: async (loginRes) => {
					const res = await this.$myRequest({
						url: "api/user/loginInfo",
						data: {
							code: loginRes.code,
							share_type:options.query.share_type || null,
							share_code:options.query.share_code || null,
							share_sort:options.query.share_sort || null,
							trackid: options.query.trackid || null,
							click_id: options.query.click_id || null,
							qz_gdt: options.query.qz_gdt || null,
							gdt_vid: options.query.gdt_vid || null,
							clickid: options.query.clickid || null,
							system_recharge: options.query.system_recharge || null,
							company_entity: options.query.company_entity || null,
							level_type: options.query.level_type || null,
							clue_token: options.query.clue_token || launchOptions.clue_token || null,
							account: options.query.account || null,
						},
					});
					if (res.code == 1) {
						console.log(res);
						getApp().globalData.share_code = res.data.share_code
						uni.setStorageSync("token", res.data.token);
						// websocetObj.sokcet()
						// websocetObj.sendMsg({"type":"ping"})
						const shareRes = await this.$myRequest({
							url: "api/system/getSystemShare",
							data: {},
						});
						if (shareRes.code == 1) {
							console.log(shareRes);
							getApp().globalData.shareArr = shareRes.data
						}
						
						// 用户行为统计
						// const resu = await this.$myRequest({
						// 	url: 'api/user/index',
						// 	data: {}
						// })
						// if (resu.code == 1) {
						// 	this.user_id = resu.data.id;
						// 	this.random = this.generateRandomString(12);
						// }
					}
				},
			});
			// #endif
			// #ifdef MP-TOUTIAO
			uni.login({
				success: async (loginRes) => {
					const res = await this.$myRequest({
						url: "api/user/user_phone_dy",
						data: {
							code: loginRes.code,
						},
					});
					if (res.code == 1) {
						uni.setStorageSync("token", res.data.token);
					}
				},
			});
			// #endif
			// #ifdef APP-PLUS || H5

			let token = uni.getStorageSync("token");
			if (!token) {
				uni.navigateTo({
					url: "/pages/login/codeLogin",
				});
			}else{
				// console.log(uni.webView,23423424243)
				// this.messageFun('token',token)
				// uni.webView.postMessage({
				// 	data: {
				// 		action: 'token',
				// 		data:token
				// 	}
				// })
				// websocetObj.sokcet()
				// websocetObj.sendMsg({"type":"ping"})
			}
			// #endif
			
			//用户行为统计
			// this.start_time = new Date();

			//启动时tabbar跳到首页
			// uni.setStorageSync('active', 1)
		},
		onShow: function() {
			console.log("App Show");
			setTimeout(()=>{
				this.$music.play_bgm()
				this.$websocetObj.sokcet()
			},0)
		},
		onHide: function() {
			console.log("App Hide");
			setTimeout(()=>{
				if(this.$music.bgmInstance){
					this.$music.bgmInstance.destroy();
					this.$music.bgmInstance = null;
				}
			},0)
			// const pages = getCurrentPages();
			// const curPage = pages[pages.length - 1];
			// this.onStatistics()
		},
		methods: {
		// 	generateRandomString(length) {
		// 		let year = this.start_time.getFullYear();
		// 		let month = (this.start_time.getMonth() + 1).toString().padStart(2, '0');
		// 		let day = this.start_time.getDate().toString().padStart(2, '0');
		// 		let hours = this.start_time.getHours().toString().padStart(2, '0');
		// 		let minutes = this.start_time.getMinutes().toString().padStart(2, '0');
		// 		let seconds = this.start_time.getSeconds().toString().padStart(2, '0');
		// 	  let result = year+month+day+hours+minutes+seconds+this.user_id;
		// 	  let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
		// 	  for (let i = 0; i < length; i++) {
		// 	    result += characters.charAt(Math.floor(Math.random() * characters.length));
		// 	  }
		// 	  return result;
		// 	},
		// 	async onStatistics(){
		// 		const res = await myRequest({
		// 			url: 'api/episode/getEpisodeInfo',
		// 			data: {}
		// 		})
		// 		if(res.code == 1){
		// 			this.episode_script_id = res.data.id;
		// 			this.episode_info_id = res.data.episode_info_id;
		// 			const year = this.start_time.getFullYear();
		// 			const month = (this.start_time.getMonth() + 1).toString().padStart(2, '0');
		// 			const day = this.start_time.getDate().toString().padStart(2, '0');
		// 			const hours = this.start_time.getHours().toString().padStart(2, '0');
		// 			const minutes = this.start_time.getMinutes().toString().padStart(2, '0');
		// 			const seconds = this.start_time.getSeconds().toString().padStart(2, '0');
		// 			this.start_time = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
		// 			const resu = await myRequest({
		// 				url: 'api/statistics/statistics',
		// 				data: {
		// 					user_id: this.user_id,
		// 					start_time: this.start_time,
		// 					random : this.random,
		// 					episode_info_id: this.episode_info_id,
		// 					episode_script_id: this.episode_script_id,
		// 				}
		// 			})
		// 			if(resu.code == 1){
		// 				console.log(resu);
		// 			}
		// 		}
		// 	},
		},
	};
</script>

<style lang="less">
	@import "./css/common.css";
	/* #ifdef H5 */
	uni-page-head {
		display: none;
	} 
	video::-webkit-media-placeholder {
	  content: url('https://siha.vxmeng.com/static/shu.jpg');
	}
	video::-moz-media-placeholder {
	  content: url('https://siha.vxmeng.com/static/shu.jpg');
	}
	video::-ms-media-placeholder {
	  content: url('https://siha.vxmeng.com/static/shu.jpg');
	}
	video::-o-media-placeholder {
	  content: url('https://siha.vxmeng.com/static/shu.jpg');
	}
	video::media-placeholder {
	  content: url('https://siha.vxmeng.com/static/shu.jpg');
	}
	/* #endif */

	image {
		width: auto;
		height: auto;
		vertical-align: middle;
	}

	.container {
		padding: 15px;
	}

	button {
		margin-bottom: 15px;
	}

	page {
		/* background-size: 100% 100%; */
		background: url("https://siha.vxmeng.com/static/index/zbg.png") no-repeat center/cover fixed;
	}

	.slh {
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.contentBox {
		width: 750rpx;
		height: calc(100vh - 200rpx);
		overflow-y: auto;
	}

	cover-view {
		word-break: break-all;
		word-wrap: break-word;
		white-space: pre-line;
	}

	radio {
		transform: scale(0.7);
	}

	/* #ifdef APP-PLUS || MP-WEIXIN */
	radio .wx-radio-input.wx-radio-input {
		background-color: transparent !important;
	}

	radio .wx-radio-input.wx-radio-input-checked {
		background-color: #1485EE !important;
	}

	/* #endif */
	uni-checkbox .uni-checkbox-input{
		background: none;
		border-radius: 50%;
		border: 2rpx solid #666666;
	}
	uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked{
		background: linear-gradient(311deg, #62B6FC 0%, #5F58FD 73%, #5F58FD 93%);
		color: #fff !important;
		border-radius: 50%;
		border: none;
	}
	uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:before{
		font-size: 24rpx !important;
	}
</style>